package models

import (
	"class-server/basic/config"
	"gorm.io/gorm"
	"time"
)

type User struct {
	Id         uint           `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	Username   string         `gorm:"column:username;type:varchar(255);not null;" json:"username"`
	Password   string         `gorm:"column:password;type:varchar(255);not null;" json:"password"`
	Nickname   string         `gorm:"column:nickname;type:varchar(255);not null;" json:"nickname"`
	UserStatus uint           `gorm:"column:user_status;type:int;comment:用户状态：1：正常 2：异常 3：冻结;not null;" json:"user_status"` // 用户状态：1：正常 2：异常 3：冻结
	CreatedAt  time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt  gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}
func (u *User) GetUserByUsername() error {
	return config.DB.Where("username = ?", u.Username).Limit(1).Find(&u).Error

}
